export function patch(oldNode, vnode) {
  // console.log(oldNode, vnode, "999999999");
  console.log(oldNode.nodeType);
  if(oldNode.nodeType===1){
  
 //1 创建新dom
 let el = createEl(vnode);
 // console.log(el);
 //2 替换       1.获取父节点   2插入   3 删除oldNode
 let parentNode = oldNode.parentNode;

 // parentNode.removeChild(oldNode);
 parentNode.insertBefore(el, oldNode.nextsibing);
 parentNode.removeChild(oldNode);
 return el;
  }else{  //diff

  }
 
}

function createEl(vnode) {
  // console.log(vnode);
  let { tag, children, key, data, text } = vnode;

  if (typeof tag === "string") {
    vnode.el = document.createElement(tag);

    //children
    if (children.length) {
      children.forEach((child) => {
        vnode.el.appendChild(createEl(child));
      });
    }
  } else {
    // console.log(document.createTextNode(text));
    vnode.el = document.createTextNode(text);
  }
  return vnode.el;
}
